#ifndef SM700_H
#define SM700_H

#include <QWidget>
#include <qtimer.h>
#include <qstring.h>
#include <arpa/inet.h>
#include "ui_sm700_main.h"

#include "xinfomatconfigmanager.h"
#include "xdatabootconf.h"
#include "xdataudpdconf.h"

//TODO: move them with New Weight Measure Widget
#define NOTICE		0xA1
#define TARE		0xB1
#define TAREVALUE 	0xA2
#define WEIGHT		0xB2
#define WEIGHTVALUE 0xA3
#define PRICE		0xB3
#define PRICEVALUE  0xA4
#define INFONOTES	0xA5	
#define TOTALPRICE  0xB4
#define TOTALPRICEVALUE	0xB5
#define ZERO  		0xB6
#define MANPREPACK	0XC1
#define NETLAMP		0XC2
#define MAX			0XC3
#define MIN			0XC4
#define INCREMENT	0XC5
#define TARELIMIT	0XC6
#define TARERIGHT	0XD1
#define WEIGHTRIGHT	0XD2
#define PRICERIGHT	0XD3
#define TOTALPRICERIGHT	0XD4

//TODO: put them with MainWidget
#define CMD_INIT	  0x1
#define CMD_REBOOT	  0x2
#define CMD_DEFAULT   0x4
#define CMD_UPDATE 	  0x8
#define CMD_HALT	  0x10
#define CMD_VOLUME    0x20
#define CMD_VERSION   0x40
#define CMD_BACKLIGHT 0x80

//Socket Define: Function Command
const char Symbol_Ini_Currency[]  = "CurrencySymbol";
const char Symbol_Ini_Position[]  = "CurrencySymbolPosition";
const char Symbol_Ini_Separator[] = "QuantityUnitPriceSeparator";
const char Symbol_Ini_File[] = "/usr/infomat/symbol.ini";

class QTimer;
class QUdpSocket;
class QProcess;
class XQueueWidget;
class XInfomatLayoutManager;
class XLayout1;

class MainWidget: public QWidget, private Ui::SM700
{
	Q_OBJECT

public:
	MainWidget(QWidget* parent = 0, Qt::WFlags f = 0);

public slots:
	void onReadSocket();
	void onFromExitScreenSaver();
	void onWMRepaint();
	void onQueueWidgetRepaint();

protected:
	inline uint32_t retrieveInt32(const unsigned char *bytes) {
		return ntohl(*reinterpret_cast<const uint32_t*> (bytes)); 
	} 

	void createWidgets(void);
	void filterProtocol(QByteArray& datagram);
	void processWeightMeasureSocket(const QByteArray &datagram);
	void processPluSocket(const QByteArray &datagram);
	void processFunctionCommandSocket(const QByteArray &datagram);
	void processQueueSocket(const QByteArray & datagram);
	void processCommandSocket(const QByteArray & datagram);
	/* COPY ORIGINAL CODE */
	void readCmd(char cmd);
	void processCmd();
	void readVersion();
	int  parseValue(QString _buffer);
	/* <<<< Copy Done */

public slots:

private:
	XDataBootConf m_xbootconf;
	XDataUdpdConf m_xudpdConf;
	XInfomatConfigManager m_xconfigProtocolMgr;

	XQueueWidget       *m_xqueueWidget;       //control Layout6,7,8,9,10
	XInfomatLayoutManager *m_xlayoutManager;  //control Layout2,3,4,5,6,8,9
	XLayout1     *m_xlayout1;

	QUdpSocket   *m_socket;
	QString		  m_senderIp;	
	quint16       m_senderPort;
	int           m_pluNo;
	bool 		  m_isUpdateZero;    //TODO: move it with W&M
	bool          m_isDisplayZero;   //TODO: move it with W&M
	bool 		  m_initWithFullScreen;
	int			  m_layout;
	QLabel       *m_lblPowerOff;
	QTimer        m_tmCmdCtrl;
	int           m_event;
	bool          m_hasSentQueue;    //for resume

	//TODO : move them with W&M 
	QString m_strMax, m_strMin, m_strIncrement, m_strLimit, m_strUnitInfo; 
	bool   m_isMax, m_isMin, m_isIncrement, m_isLimit;
	QString m_currencySymbol;
	QString m_currencySymbolPos;
	QString m_quantityUnitPriceSeparator;
	int   m_weighMeasureSocketCounter;
	int   m_screenState;
	
	/* Command Socket (COPY ORIGINAL CODE) */
	int 	    lighton;
	int 	    volumeData;
	QProcess   *cmdProc;
	bool 	    cmdPending;
	QUdpSocket *udpSocketOut;
	int         udpPort;
	/* <<<< Copy Done */

	/* -------- Revision1 ----------Add>>--*/
	enum EScreenModeState {
		EFullScreen = 0,
		EPartialScreen,
		ENotSet,
	};

	enum EScreenModeSwitch {
		EScreenModeOff =0,
		EScreenModeOn
	};

	enum EPluValid {
		EInvalidValue = -1,
		EBothPluValid,
		EHtmlPluValidOnly,
		EMoviePluValidOnly,
	};
	enum EInfomatEvents {
		ENoEvent = -1,
		ERoutine,   			//0
		EPlu,
		EQueue,
		EEnterMenuMode,
		EExitMenuMode,
		EEnterScreenSaver,    	//5
		EExitScreenSaver,
	};
	/* ----------------------------End<<--*/
};
#endif

/* 
 * Revision
 * 1            22 Feb 2011      New      Screen Mode
 */
